/*
 * @ClassName api_test.dart
 * @Description TODO
 * @Author SuPeiSen
 * @Date 2020/7/17 14:24
 */

import 'package:flutter/material.dart';
import 'package:flutter_su/common/fun.dart';
import 'package:flutter_su/common/show.dart';
import 'package:flutter_su/model/login_model.dart';
import 'package:flutter_su/pages/test/common_widget.dart';
import 'package:flutter_su/services/login_register_api.dart';

class ApiTest extends StatefulWidget {
  @override
  _ApiTestState createState() => _ApiTestState();
}

class _ApiTestState extends State<ApiTest> with CommonTestWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("接口测试"),
        centerTitle: true,
      ),
      body: _body(),
    );
  }

  Widget _body(){
    return Container(
      width: double.infinity,
      child: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            _loginRegister(),
          ],
        ),
      ),
    );
  }

  // 登录注册
  Widget _loginRegister(){
    return Column(
      children: <Widget>[
        title("注册登录"),
        Wrap(
          children: <Widget>[

            // 注册
            RaisedButton(
              child: Text("注册"),
              onPressed: () async {
                await LoginRegisterApi().register(
                  userName: "570779284@qq.com",
                  pwd: "123456",
                );
              },
            ),

            RaisedButton(
              child: Text("登录"),
              onPressed: () async {
                LoginModel model = await LoginRegisterApi().login(
                  bslEmail: "570779284@qq.com",
                  pwd: "123456",
                );
                if(model != null){
                  Show.showBottomSheet(msg: model.data.toJson().toString());
                }
              },
            ),

          ],
        ),
      ],
    );
  }
}
